<template>
	<view class="container">
		<view class="upperinput">
			<text class="fillwidth" style="margin-left: 50px; font-size: 20px;">每月总预算：</text>
			<input class="biginput" v-model="budgetpermonth" type="number" value="" />
			<text class="fillwidth" style="margin-left: 50px; font-size: 20px;">吃饭最低消费：</text>
			<input class="biginput" v-model="mininumconsume" type="number" value="" />
			<text class="fillwidth" style="margin-left: 50px; font-size: 20px;">本月总预算：</text>
			<input class="biginput" v-model="budgetthismonth" type="number" value="" />
			<view class="horizonbutton">
				<button type="primary" style="margin-top: 10px;" v-on:click="saveForm">保存更改</button>
				<button type="default" style="margin-top: 10px;" v-on:click="gotoBudget()">预算加减</button>
			</view>
			
		</view>
		<view class="flexspace">
			
		</view>
		<view style="text-align: center; font-size: 12px;"><text>软件数据仅保存在本地，更换手机前请自行摘抄备份</text></view>
		<view style="text-align: center; font-size: 12px; color: red;"><text>从“最近的小程序”列表移除时，会清除小程序数据，请注意</text></view>
	</view>
</template>

<script>
	var NC = require("../../../common/common.js");
	
	function failmsg(msg){
		uni.showToast({
			icon:"none",
			image:"../../../static/img/warn.png",
			title:msg
		});
	}
	function successmsg(msg){
		uni.showToast({
			icon:"success",
			title:msg
		});
	}
	export default {
		data() {
			return {
				budgetpermonth:0,
				budgetthismonth:0,
				mininumconsume:0
			}
		},
		onShow() {
			NC.NextCalc.loadState();
			this.budgetpermonth = NC.NextCalc.getDefaultBudget();
			this.mininumconsume = NC.NextCalc.minMeal;
			this.budgetthismonth = NC.NextCalc.totalAmount;
		},
		methods: {
			saveForm:function(){
				var defBudget = this.budgetpermonth;
				var minmeal = this.mininumconsume;
				var currentBudget = this.budgetthismonth;
				
				if(isNaN(minmeal) || minmeal<0){
				    failmsg("请输入正确的最低消费");
				    return;
				}
				if(isNaN(defBudget) || defBudget<0){
				    failmsg("请输入正确的每月预算");
				    return;
				}
				if(isNaN(currentBudget) || currentBudget<0){
				    failmsg("请输入正确的本月总预算");
				    return;
				}
				NC.NextCalc.setDefaultBudget(defBudget);
				NC.NextCalc.minMeal = minmeal;
				NC.NextCalc.totalAmount = currentBudget;
				NC.NextCalc.saveState();
				successmsg("设置保存成功");
			},
			gotoBudget:function(){
				uni.navigateTo({
					url:"../addbudget/addbudget"
				})
			}
		}
	}
</script>

<style>
	page{
		height: 100%;
	}
	.container{
		height: 100%;
		display: flex;
		flex-direction: column;
	}
	.upperinput{
		width: 100vw;
		height: 60vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.fillwidth{
		width: 100%;
	}
	.biginput{
		font-size: 30px;
		height: 36px;
		width: calc(100% - 50px);
		text-align: left;
		margin-left: 25px;
		margin-right: 25px;
		border-bottom: solid #00ca0d 1px;
	}
	.horizonbutton{
		width: calc(100% - 50px);
		margin-left: 25px;
		margin-right: 25px;
	}
	.flexspace{
			flex-grow: 11 ;
		}
</style>
